#include<stdio.h>
#include<string.h>


void Encryption(char*str,int number)
{
	int i;
	int len=strlen(str);
	char ch;
	for(i=0;i<len;i++)
	{
		ch=str[i];
		if(ch>='a'&&ch<='z')
		{
			if(ch+number%26<='z')
			{
				str[i]=(char)(ch+number%26);
			}
			else 
			{
				str[i]=(char)('a'+(number-('z'-ch)-1)%26);
			}
		}
		if(ch>='A'&&ch<='Z')
		{
			if(ch+number%26<='Z')
			{
				str[i]=(char)(ch+number%26);
			}
			else
			{
				str[i]=(char)('A'+(number-('Z'-ch)-1)%26);
			}
		}
	}
	printf("\nout:");
	puts(str);
}
void Decryption(char*str,int number)
{
	int i;
	int len=strlen(str);
	char ch;
	for(i=0;i<len;i++)
	{
		ch=str[i];
		if(ch>='a'&&ch<='z')
		{
			if(ch-number%26>='a')
			{
				str[i]=(char)(ch-number%26);
			}
			else 
			{
				str[i]=(char)('z'-(number-(ch-'a')-1)%26);
			}
		}
		if(ch>='A'&&ch<='Z')
		{
			if(ch-number%26>='A')
			{
				str[i]=(char)(ch-number%26);
			}
			else
			{
				str[i]=(char)('Z'-(number-(ch-'A')-1)%26);
			}
		}
	}
	printf("\nout:");
	puts(str);
}


int main()
{
	char str[50];
	int option,number,i;
	printf("please input strings:");
	scanf("%s",str);

	printf("\n1:Encryption");//数据加密
	printf("\n2:Decryption");//数据解密
	printf("\n3:Violent Crack\n");//暴力破解
	
	printf("please choose:");
	scanf("%d",&option);
	
	switch(option)
	{
		case 1:
			printf("\nplease input number:");
			scanf("%d",&number);
			Encryption(str,number);
			break;
		case 2:
			printf("\nplease input number:");
			scanf("%d",&number);
			Decryption(str,number);
			break;
		case 3:
			for(i=0;i<=25;i++)
			{
				printf("%d",i);
				Decryption(str, 1);
			}
			break;
		default:
		printf("choose error!\n");
			break;
	}

	
	return 0;
}
